//
//  BaseModelManager.m
//  MobileGuide
//
//  Created by 鞠 文杰 on 14-2-27.
//  Copyright (c) 2014年 CSICS. All rights reserved.
//

#import "BaseModelManager.h"

@implementation BaseModelManager{
    NSMutableSet *registedClass;
    NSMutableDictionary *classPropertiesMap;
}


+ (BaseModelManager*)sharedSingleton
{
    static dispatch_once_t pred;
    static BaseModelManager *instance=nil;
    
    dispatch_once(&pred,^{
        instance=[[self alloc] initSingleton];
    });
    return instance;
}

- (id)init
{
    NSAssert(NO, @"不能通过init方法创建单例对象");
    return nil;
}

- (id) initSingleton
{
    self = [super init];
    if(self){
        registedClass = [NSMutableSet new];
        classPropertiesMap = [NSMutableDictionary new];
    }
    return self;
}

- (void)registerInMemory:(Class)clazz properties:(NSDictionary*)properties;
{
    @synchronized(self)
    {
        if(![registedClass containsObject:clazz])
        {
            [registedClass addObject:clazz];
            [classPropertiesMap setValue:properties forKey:[NSString stringWithUTF8String:object_getClassName(clazz)]];
        }
    }
    
}

- (NSDictionary*)getClassProperties:(Class)clazz
{
    if ([registedClass containsObject:clazz]) {
        return [classPropertiesMap objectForKey:[NSString stringWithUTF8String:object_getClassName(clazz)]];
    }else{
        return nil;
    }
}

@end
